<?php

namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class TagsController extends Controller
{
    public function tags_add(Request $request)
    {
        $method = $request->method();
        if($method == 'GET')
        {
            return view('Admin/Tag/tags_add');
        }
        if($method == 'POST')
        {
            $res = $request->input();
            $res = $res['tagsName'];
            if(empty($res))
            {
                return ['status'=>0,'info'=>'标签名不能为空'];
            }
            $data = DB::select('select * from bz_tag where tag_name = ?',[$res]);
            if(empty($data))
            {
                $bool = DB::insert("insert into bz_tag(tag_name) values(?)",[$res]);
                if($bool)
                {
                    return ['status'=>1,'info'=>'添加成功'];
                }else{
                    return['status'=>0,'info'=>'添加失败'];
                }
            }else{
                return ['status'=>0,'info'=>'此标签名称已存在'];
            }

        }

    }

    public function tags_list()
    {
        $data = DB::table('tag')->select()->get();
        $count = DB::table('tag')->select()->count();
        //$list = ['data'=>$data,'ccount'=>$count];
        return view('Admin/Tag//tags_list')->with('data',$data)->with('count',$count);

    }

    public function tags_del(Request $request)
    {
        $method = $request->method();
        if($method == 'POST')
        {
            $res = $request->input();
            $result = DB::table('tag')->where('tag_id',$res)->delete();
           if($result)
           {
               return ['status' => 1, 'info' => '已删除'];
           }
           else
           {
               return ['status'=>0,'info'=>'删除失败'];
           }
        }
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function test()
    {
        $data = DB::table('tag')->select()->get();
        $count = DB::table('tag')->select()->count();
        $list = ['data'=>$data,'count'=>$count];
        print_r($list);
        //return view('Goods/tagsList')->with('data',$data);


    }
}
